package com.wuxx.quartz;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobListener;

/**
 * created by wuxx on 2017/12/15.
 * 监听器，用于监控任务的执行情况
 */
public class QuartzListener implements JobListener {
    private static Logger log = LogManager.getLogger(QuartzListener.class);

    @Override
    public String getName() {
        String name = this.getClass().getSimpleName();
        log.debug("监听器的名称为： "+name);
        return System.currentTimeMillis() + "QuartzListener";
    }

    @Override
    public void jobToBeExecuted(JobExecutionContext jobExecutionContext) {
        String name = jobExecutionContext.getJobDetail().getKey().getName(); //获取Job的name
        log.debug("被监听的job的name是："+name+"   Scheduler在JobDetail将要被执行时调用的方法");
    }

    @Override
    public void jobExecutionVetoed(JobExecutionContext jobExecutionContext) {
        String name = jobExecutionContext.getJobDetail().getKey().getName(); //获取Job的name
        log.debug("Scheduler在JobDetail即将执行，但又被TriggerListerner否决时会调用的方法");
    }

    @Override
    public void jobWasExecuted(JobExecutionContext jobExecutionContext, JobExecutionException e) {
        String name = jobExecutionContext.getJobDetail().getKey().getName(); //获取Job的name
        log.debug("Scheduler是在JobDetail被执行之后调用这个方法的");
    }
}
